package com.bdqn.springweb.Controller;


import com.bdqn.springweb.Service.UserService;
import com.bdqn.springweb.pojo.User;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {
   @Resource
    private UserService userService;
    @RequestMapping(value = "/login")
    public String login(String userName, String password, Model model, HttpSession session) {
        User user = userService.login(userName, password);
        session.setAttribute("loginUser",user);
        if (user != null) {
            session.setAttribute("loginUser", user);
            return "redirect/main";
        }else {
            model.addAttribute("msg", "用户名或密码错误，登录失败！");
            return "forward/login.jsp";
        }
    }
    @RequestMapping(value = "/main")
    public String main() {
        return "main";
    }

}
